package com.zulu.karaoke.gui.custom;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface.OnShowListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.zulu.karaoke.R;

public class CustomAlertDialog {
	private Dialog mCustomDialog;
	private TextView tvTitle;
	private Button mButton1, mButton2;
	private Button mButton3, mButton4;
	private LayoutInflater mInflater;
	private OnItemClickListener itemClickListner;
	private ListView lvContent;
//	private Context mContext;
	
	public CustomAlertDialog(Context context, View contentView, Boolean backCancel) {
		mInflater = LayoutInflater.from(context);
        View customLayout = mInflater.inflate(R.layout.zulu_custom_dialog_layout, null);
        FrameLayout layoutContent = (FrameLayout)customLayout.findViewById(R.id.layout_content);
        mButton1 = (Button)customLayout.findViewById(R.id.button1);
        mButton2 = (Button)customLayout.findViewById(R.id.button2);
        mButton3 = (Button)customLayout.findViewById(R.id.button3);
        mButton4 = (Button)customLayout.findViewById(R.id.button4);
        mButton1.setVisibility(View.GONE);
        mButton2.setVisibility(View.GONE);
        mButton3.setVisibility(View.GONE);
        mButton4.setVisibility(View.GONE);
        tvTitle = (TextView)customLayout.findViewById(R.id.tv_dialog_title);
        layoutContent.addView(contentView);
        mCustomDialog = new Dialog(context,R.style.CustomDialogTheme);
        mCustomDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mCustomDialog.setContentView(customLayout);
        mCustomDialog.setCanceledOnTouchOutside(false);
        mCustomDialog.setCancelable(backCancel);
	}
    
	public CustomAlertDialog(Context context, View contentView, int width, int height) {
		mInflater = LayoutInflater.from(context);
        View customLayout = mInflater.inflate(R.layout.zulu_custom_dialog_layout, null);
        FrameLayout layoutContent = (FrameLayout)customLayout.findViewById(R.id.layout_content);
        mButton1 = (Button)customLayout.findViewById(R.id.button1);
        mButton2 = (Button)customLayout.findViewById(R.id.button2);
        mButton3 = (Button)customLayout.findViewById(R.id.button3);
        mButton4 = (Button)customLayout.findViewById(R.id.button4);
        mButton1.setVisibility(View.GONE);
        mButton2.setVisibility(View.GONE);
        mButton3.setVisibility(View.GONE);
        mButton4.setVisibility(View.GONE);
        tvTitle = (TextView)customLayout.findViewById(R.id.tv_dialog_title);
        layoutContent.addView(contentView);
        mCustomDialog = new Dialog(context,R.style.CustomDialogTheme);
        mCustomDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mCustomDialog.setContentView(customLayout);
        mCustomDialog.getWindow().setLayout(width, height);
        mCustomDialog.setCanceledOnTouchOutside(false);
	}
	
//	public CustomAlertDialog(Context context) {
//		mContext = context;
//		mInflater = LayoutInflater.from(context);
//	}
	
	public void setOnItemClickListener(OnItemClickListener itemClick)
	{
		itemClickListner = itemClick;
		lvContent.setOnItemClickListener(itemClickListner);
	}
	
	public void setOnShowDialogListener(OnShowListener listener){
		if(mCustomDialog != null)
			mCustomDialog.setOnShowListener(listener);
	}
	public ListView getListView()
	{
		return lvContent;
	}
	
	public void showDialog()
	{
		if(mCustomDialog != null && !mCustomDialog.isShowing()){
			mCustomDialog.show();
		}
	}
	
	public void hideDialog()
	{
		if(mCustomDialog != null && mCustomDialog.isShowing()){
			mCustomDialog.dismiss();
		}
	}
	
	public void setTitle(String title)
	{
		if(tvTitle != null)
			tvTitle.setText(title);
	}
	
	public void setButton(String title, View.OnClickListener onClick ){
		mButton1.setVisibility(View.VISIBLE);
		mButton1.setText(title);
		mButton1.setOnClickListener(onClick);
	}
	
	public void setButton2(String title, View.OnClickListener onClick){
		mButton2.setVisibility(View.VISIBLE);
		mButton2.setText(title);
		mButton2.setOnClickListener(onClick);
	}
	
	public void setButton3(String title, View.OnClickListener onClick){
		mButton3.setVisibility(View.VISIBLE);
		mButton3.setText(title);
		mButton3.setOnClickListener(onClick);
	}
	
	public void setButton4(String title, View.OnClickListener onClick){
		mButton4.setVisibility(View.VISIBLE);
		mButton4.setText(title);
		mButton4.setOnClickListener(onClick);
	}
	
}
